class CreateOccasionsTable < ActiveRecord::Migration

  def self.up
  create_table "occasion_participations" do |t|
    t.datetime "created_on"
    t.datetime "updated_on"
    t.integer  "user_id",                       :null => false
    t.integer  "occasion_id",                   :null => false
    t.boolean  "waiting",    :default => false, :null => false
    t.boolean  "owned",      :default => false, :null => false
    t.boolean  "favorite",   :default => true,  :null => false
  end

  create_table "occasions" do |t|
    t.datetime "created_on"
    t.datetime "updated_on"
    t.string   "name",        :limit => 100, :default => "",    :null => false
    t.text     "description"
    t.boolean  "protected",                  :default => false, :null => false
    t.string   "oid",         :limit => 100, :default => "",    :null => false
    t.string   "category",    :limit => 50,  :default => "",    :null => false
  end

  add_index "occasions", ["oid"], :name => "index_occasions_on_oid", :unique => true

  create_table "occasion_board_entries" do |t|
    t.datetime "created_on"
    t.datetime "updated_on"
    t.string   "title",                      :limit => 100, :default => "",     :null => false
    t.text     "contents",                                                      :null => false
    t.datetime "date",                                                          :null => false
    t.integer  "user_id",                                                       :null => false
    t.string   "category"
    t.string   "entry_type"
    t.boolean  "ignore_times",                              :default => false,  :null => false
    t.datetime "last_updated",                                                  :null => false
    t.integer  "user_entry_no",                                                 :null => false
    t.integer  "occasion_board_entry_comments_count",                :default => 0,      :null => false
    t.string   "symbol",                     :limit => 100, :default => "",     :null => false
    t.string   "editor_mode",                               :default => "hiki", :null => false
    t.integer  "lock_version",                              :default => 0,      :null => false
    t.string   "publication_type"
    t.string   "publication_symbols_value"
    t.integer  "entry_trackbacks_count",                    :default => 0,      :null => false
  end

  add_index "occasion_board_entries", ["symbol"], :name => "index_board_entries_on_symbol"
  add_index "occasion_board_entries", ["date"], :name => "index_board_entries_on_date"
  add_index "occasion_board_entries", ["user_id"], :name => "index_board_entries_on_user_id"

  create_table "occasion_board_entry_comments" do |t|
    t.datetime "created_on"
    t.datetime "updated_on"
    t.integer  "occasion_board_entry_id",                 :null => false
    t.text     "contents",                       :null => false
    t.integer  "user_id",                        :null => false
    t.integer  "parent_id"
  end

  add_index "occasion_board_entry_comments", ["occasion_board_entry_id"], :name => "index_occasion_board_entry_comments_on_occasion_board_entry_id"
  add_index "occasion_board_entry_comments", ["parent_id"], :name => "index_occasion_board_entry_comments_on_parent_id"

  create_table "occasion_board_entry_points" do |t|
    t.datetime "created_on"
    t.datetime "updated_on"
    t.integer  "occasion_board_entry_id",                    :null => false
    t.integer  "point",              :default => 0, :null => false
    t.integer  "access_count",       :default => 0, :null => false
    t.integer  "today_access_count", :default => 0, :null => false
  end

  add_index "occasion_board_entry_points", ["occasion_board_entry_id"], :name => "index_occasion_board_entry_points_on_occasion_board_entry_id"

  create_table "occasion_entry_publications" do |t|
    t.integer "occasion_board_entry_id",                 :null => false
    t.string  "symbol",         :default => "", :null => false
  end

  create_table "occasion_entry_accesses" do |t|
    t.integer  "occasion_board_entry_id", :null => false
    t.integer  "visitor_id",     :null => false
    t.datetime "updated_on",     :null => false
  end

  add_index "occasion_entry_accesses", ["occasion_board_entry_id"], :name => "index_occasion_entry_accesses_on_occasion_board_entry_id"

  create_table "occasion_entry_editors" do |t|
    t.integer "occasion_board_entry_id",                 :null => false
    t.string  "symbol",         :default => "", :null => false
  end

  create_table "occasion_entry_tags" do |t|
    t.datetime "created_on"
    t.integer  "occasion_board_entry_id", :null => false
    t.integer  "occasion_tag_id",         :null => false
  end

  add_index "occasion_entry_tags", ["occasion_tag_id"], :name => "index_occasion_entry_tags_on_occasion_tag_id"
  add_index "occasion_entry_tags", ["occasion_board_entry_id"], :name => "index_occasion_entry_tags_on_board_entry_id"

  create_table "occasion_tags" do |t|
    t.datetime "created_on"
    t.datetime "updated_on"
    t.string   "name",       :limit => 100, :default => "", :null => false
    t.string   "occasion_tag_type",   :limit => 16
  end

  add_index "occasion_tags", ["name"], :name => "index_occasion_tags_on_name"

  # occasion_tagのデフォルト値の登録
  occasion_system_tags  = ["質問","要望","重要","連絡","解決","商品","確定"]
  occasion_standard_tags = ["書評","もんた","日記","技術","ネタ","ニュース"]

  occasion_tag_hash = Hash.new
  occasion_system_tags.each do |name|
    occasion_tag = OccasionTag.create(:name => name, :occasion_tag_type => "SYSTEM")
    occasion_tag_hash.store(name, occasion_tag.id)
  end
  occasion_standard_tags.each do  |name|
    occasion_tag = OccasionTag.create(:name => name, :occasion_tag_type => "STANDARD")
    occasion_tag_hash.store(name, occasion_tag.id)
  end

  end
end
